package com.taptech.doufu.sdk.qiniu.service;

import java.io.File;

import android.content.Context;

import com.taptech.doufu.sdk.qiniu.auth.JSONObjectRet;
import com.taptech.doufu.sdk.qiniu.resumableio.PutExtra;
import com.taptech.doufu.sdk.qiniu.resumableio.ResumableIO;
import com.taptech.doufu.sdk.qiniu.utils.InputStreamAt;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.net.httputils.HttpResponseObject;

public class QiniuService implements HttpResponseListener {
	public static QiniuService instance = new QiniuService();
	public static final String QINIU = "qiniu";
	public static final String TOKEN = "token";
	public static String QINIU_TOKEN = "";

	public final static int HANDLE_GET_TOKEN = 5001;

	private QiniuService() {
		init();
	}

	private void init() {
		QINIU_TOKEN = WeMediaApplication.applicationContext
				.getSharedPreferences(QINIU, Context.MODE_PRIVATE).getString(
						TOKEN, null);
		if (QINIU_TOKEN == null) {
			loadAttentions();
		}

	}

	public static QiniuService getInstance() {
		return instance;
	}

	public void loadAttentions() {
		
	}

	@Override
	public void handleResponse(int handleType, HttpResponseObject response) {

	}

	public void upload(File file, PutExtra extra, JSONObjectRet ret) {
		ResumableIO.defaultInstance(QINIU_TOKEN)
				.putFile(null, file, extra, ret);
	}

	public void upload(String fileName,byte datas[], PutExtra extra, JSONObjectRet ret) {
		InputStreamAt is = new InputStreamAt(datas);
		ResumableIO.defaultInstance(QINIU_TOKEN).put(fileName, is, extra, ret);
	}

}
